package app.Disthanitian.thaistyle.EmerMez;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.*;

public class MyPaperThread extends Thread {
	private Socket socket = null;
	private MyPaper client = null;
	private DataInputStream streamIn = null;

	public MyPaperThread(MyPaper _client, Socket _socket) {
		client = _client;
		socket = _socket;
		open();
		start();
	}

	private void open() {
		try {
			streamIn = new DataInputStream(socket.getInputStream());

		} catch (IOException ioe) {
			System.out.println("Error getting input stream:" + ioe);
			client.close();
		}
	}

	public void close() {

		try {
			if (streamIn != null)
				streamIn.close();
		} catch (IOException ioe) {
			System.out.println("Error closing input stream:" + ioe);

		}

	}

	public void run() {
		while (true) {

			try {
				client.handle(streamIn.readUTF());
			} catch (IOException ioe) {
				System.out.println("Listening error:" + ioe.getMessage());
				client.close();
			}
		}

	}

}
